Cracking the Coding Interview3 Notes
Table of Contents
Chapter 8 debugging
The following approach:
- Examine the code and understand what it's expected to do. Ask your interviewer what types of data it's expected to handle, where it'll be used. etc.
- Look for syntax errors: does everything type check? is the class declaration correct?
- Look for "hot spots":
- If you see float and doubles, check for precision errors
- If you see division, check for rounding errors
- If you see memory allocation, check for memory leaks
- If you see unsigned ints, check to see if the int might ever be negative
- If you see bit manipulation, check for correctness
- Run through the code with a few examples:
- The "normal" case
- The boundary cases(null, 0, 1, MAX, etc)
- Does it do everything it's expected to? For example, if the code is supposed to return everyone in a database under 21, does it only look for students? Maybe it should be looking for teachers as well?
- Does it handle unexpeced cases? What if it takes in a list and it has a loop?